-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Polyfill span.Contains(T) #123656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Polyfill span.Contains(T) #123656
Conversation
|
Tagging subscribers to this area: @dotnet/area-meta |
src/libraries/System.CodeDom/src/Microsoft/CSharp/CSharpCodeGenerator.cs
Show resolved
Hide resolved
...raries/System.Configuration.ConfigurationManager/src/System/Configuration/StringValidator.cs
Outdated
Show resolved
Hide resolved
...raries/System.Configuration.ConfigurationManager/src/System/Configuration/StringValidator.cs
Show resolved
Hide resolved
...libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Comment.cs
Outdated
Show resolved
Hide resolved
...libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Comment.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds polyfills for Contains(T) methods on ReadOnlySpan<T> and introduces corresponding Contains(char), StartsWith(char), and EndsWith(char) extension methods for strings to support downlevel targets (primarily .NET Standard 2.0 and .NET Framework).
Changes:
- Adds
StringPolyfills.cswith extension methods forstring.Contains(char),string.StartsWith(char), andstring.EndsWith(char)for pre-.NET Standard 2.1 targets - Adds
ReadOnlySpan<T>.Contains(T)polyfill toMemoryExtensionsPolyfills.cs - Converts numerous
IndexOfchecks throughout the codebase to use the more readableContains,StartsWith, andEndsWithmethods - Removes CA warning suppressions (CA1866, CA2249, CA1865, CA1867) that are no longer needed after the conversions
- Adds
IncludeSpanPolyfillsproperty to projects targeting downlevel frameworks
Reviewed changes
Copilot reviewed 74 out of 74 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/Common/src/System/StringPolyfills.cs | New polyfill file providing Contains(char), StartsWith(char), and EndsWith(char) for strings |
| src/libraries/Common/src/System/MemoryExtensionsPolyfills.cs | Adds Contains<T> polyfill for ReadOnlySpan<T> |
| src/libraries/Directory.Build.targets | Includes StringPolyfills.cs in the IncludeSpanPolyfills build configuration |
| src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs | Converts StartsWith("v") to StartsWith('v') |
| src/tasks/Crossgen2Tasks/RunReadyToRunCompiler.cs | Converts IndexOf("warning:") != -1 to Contains("warning:") |
| src/tasks/Crossgen2Tasks/CommonFilePulledFromSdkRepo/NuGetUtils.NuGet.cs | Converts IndexOf checks to Contains |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/TypeNameBuilder.cs | Converts IndexOf(c) != -1 to Contains(c) for span |
| src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexInterpreter.cs | Converts IndexOf < 0 to !Contains for span |
| src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Comment.cs | Converts IndexOf checks, one using Contains with StringComparison |
| src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/EnumConverter.cs | Converts IndexOf(',') >= 0 to Contains(',') |
| src/libraries/System.Text.Json/src/System/Text/Json/Reader/*.cs | Multiple conversions of IndexOf delimiter checks to Contains |
| src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.cs | Converts IndexOf check to Contains |
| src/libraries/System.Speech/src/Result/RecognizedPhrase.cs | Converts Contains("$") to Contains('$') |
| src/libraries/System.Speech/src/Internal/SrgsParser/XmlParser.cs | BUG: Converts to ContainsAny without .AsSpan() call |
| src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceController.cs | Converts StartsWith and Contains checks, removes outdated comment |
| src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Aes.cs | Converts IndexOfAnyExcept >= 0 to ContainsAnyExcept |
| src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/*.cs | Converts IndexOf("<") to IndexOf('<') |
| src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/*.cs | Converts Contains checks and removes #if NET conditionals |
| src/libraries/System.Net.ServerSentEvents/src/System/Net/ServerSentEvents/SseParser_1.cs | Converts IndexOf < 0 to !Contains |
| src/libraries/System.Memory/src/System/Buffers/SequenceReader.Search.cs | Converts IndexOf != -1 to Contains in loop condition |
| src/libraries/System.Management/src/System/Management/*.cs | Converts IndexOfAny and StartsWith checks |
| src/libraries/System.IO.Packaging/src/System/IO/Packaging/*.cs | Converts Contains checks and removes #if NET conditionals |
| src/libraries/System.DirectoryServices*/src/**/*.cs | Converts StartsWith and Contains checks |
| src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs | Optimizes EndsWith(".") to direct character comparison |
| src/libraries/System.Data./src/**/.cs | Multiple conversions removing comments about .NET Core 2.1 availability |
| src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/StringValidator.cs | BUG: Changes field type to SearchValues but still formats it as string in error message |
| src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/*.cs | Multiple conversions and removal of #if NET conditionals |
| src/libraries/System.CodeDom/src/Microsoft/**/*.cs | Converts Contains checks and removes #if NET conditionals |
| src/libraries/Microsoft.Extensions./src/**/.cs | Multiple conversions and conditional removal |
| src/libraries/Common/src/**/*.cs | Multiple conversions in common code |
| src/coreclr/tools//src/**/.cs | Multiple conversions and warning suppressions removed |
| Multiple .csproj files | Removes CA warning suppressions and adds IncludeSpanPolyfills/polyfill references |
...raries/System.Configuration.ConfigurationManager/src/System/Configuration/StringValidator.cs
Show resolved
Hide resolved
b1cd48c to
9212f13
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 75 out of 75 changed files in this pull request and generated no new comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 75 out of 75 changed files in this pull request and generated no new comments.
No description provided.